package com.hzqy.web.ac;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.HttpUtil;
import com.hzqy.commons.utils.SystemConfigUtils;

@Controller
@RequestMapping("/cache")
public class ClearCacheAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	
	@RequestMapping("/clear_web_cache")
	@ResponseBody
	public Object clearWebCache() {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			String webCacheUrls = SystemConfigUtils.getSysConfig("all_web_alear_cache_url");
			if(webCacheUrls != null) {
				String[] webCacheUrlArr = webCacheUrls.split("\\|");
				String epg_info = "?epg_info=" + URLEncoder.encode("<server_ip>220.191.139.79</server_ip><group_name>10013</group_name><group_path></group_path><oss_user_id>0571000199</oss_user_id><page_url>http://220.191.139.79:8080/iptvepg/frame1029/vis_to_page.jsp</page_url><partner>GDHDDefault</partner>", "UTF-8");
				
				for(int i = 0; i < webCacheUrlArr.length; i ++) {
					Map<String, String> map = HttpUtil.get(webCacheUrlArr[i] + epg_info);
					resultMap.put(String.valueOf(i), map);
				}
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return resultMap;
	}
	
		
}
